#include<iostream>
#include<set>
#include<vector>
#include<unordered_set>
using namespace std;

class Solution0 {
public:
    int longestConsecutive(vector<int>& nums) {
        set<int> se;
        int len = nums.size();
        for (int i = 0; i < len; i++) {
            se.insert(nums[i]);
        }
        int tmpCount = 0;
        int maxCount = 0;
        int oldDigit = 0;
        for (auto& e : se) {
            if (e != oldDigit + 1) {
                oldDigit = e;
                maxCount = max(maxCount, tmpCount);
                tmpCount = 1;
            }
            else {
                tmpCount++;
                oldDigit++;
            }
        }
        maxCount = max(tmpCount, maxCount);
        return maxCount;
    }
};


class Solution1 {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> num_set;
        for (const int& num : nums) {
            num_set.insert(num);
        }

        int longestStreak = 0;

        for (const int& num : num_set) {
            if (!num_set.count(num - 1)) {
                int currentNum = num;
                int currentStreak = 1;

                while (num_set.count(currentNum + 1)) {
                    currentNum += 1;
                    currentStreak += 1;
                }

                longestStreak = max(longestStreak, currentStreak);
            }
        }

        return longestStreak;
    }
};

